package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.ReplyService;
import com.qf.lanzhou.blog.api.service.impl.ReplyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 是柠檬甜
 * @ClassName ReplyServlet
 * @description 评论回复功能
 * @date 2020/12/18 16:27
 * @modifier 是柠檬甜
 * @date 2020-12-18 16:27
 * @Version V1.0
 */
@WebServlet("/reply.do")
public class ReplyServlet extends BaseServletPost {
    private ReplyService replyService=new ReplyServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String articleId = req.getParameter("articleId");
        String commentId = req.getParameter("commentId");
        String replyContent = req.getParameter("replyContent");
        User user = (User) req.getSession().getAttribute("user");
        long articleIdLong = Long.parseLong(articleId);
        System.out.println(articleIdLong+"文章标题，是柠檬甜");
        long commentIdLong = Long.parseLong(commentId);
        System.out.println(commentIdLong+"文章标题，是柠檬甜");
        try{
            Boolean result = replyService.addReply(commentIdLong, articleIdLong, replyContent,user.getUserName());
            System.out.println(result+"====");
            successResultWrite("回复成功",resp);
        }catch (RuntimeException e){
            String message = e.getMessage();
            failedResultWrite(message,resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
